/*
 * CAudioDevice.h
 *
 *  Created on: 2016年4月13日
 *      Author: terry
 */

#ifndef CAUDIODEVICE_H_
#define CAUDIODEVICE_H_

#include "AudioDevice.h"
#include "SDL.h"
#include "TCriticalSection.h"
#include "TEvent.h"
#include "TIOBuffer.h"

namespace av
{

class CAudioDevice: public AudioDevice
{
public:
    static void init();
    static void quit();

public:
	CAudioDevice();
	virtual ~CAudioDevice();

	virtual bool open(int channels, int rate, int bits);

	virtual void close();

	virtual bool isOpen();

	virtual void write(uint8_t* data, int size, int64_t pts);

	virtual void pause(bool toPause);

	virtual void flush();

	virtual bool isPaused();

	virtual float getVolume();

	virtual bool setVolume(float vol);

	virtual bool isMute();

	virtual bool setMute(bool muted);


	static void sdlAudioCallback(void* userdata, Uint8* stream, int len);
	void audioCallback(Uint8* stream, int len);

	void clearFrame();

protected:
	comn::CriticalSection m_cs;

	SDL_AudioDeviceID   m_audioDev;
    SDL_AudioSpec       m_audioSpec;

    bool 	    m_playing;

    int		m_volume;
    bool 	m_muted;

    comn::IOBuffer  m_buffer;

};



} /* namespace av */

#endif /* CAUDIODEVICE_H_ */
